package com.none.web.service.param.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.stereotype.Service;

import com.none.core.common.utils.TransactSQLInjectionUtil;
import com.none.core.service.BaseServiceSupport;
import com.none.web.model.Param;
import com.none.web.service.param.IParamService;


@Service("paramService")
public class ParamServiceImpl extends BaseServiceSupport implements IParamService {

	@Autowired
    JdbcTemplate jdbcTemplate;
	
	
	@Override
	public Param getParamByKey(String paramKey) {
		boolean bool = TransactSQLInjectionUtil.sql_inj(paramKey);
		Param param =new Param();
		if(bool){
			return param;
		}else{
			String sql="select * from param where param_key='"+paramKey+"'";
			RowMapper<Param> sr=ParameterizedBeanPropertyRowMapper.newInstance(Param.class); 
			List<Param> list=this.jdbcTemplate.query(sql,sr);
			param=list.get(0);
			return param;
		}
	}


	@Override
	public List<Param> getAllParam() {
		String sql="select * from param";
		RowMapper<Param> sr=ParameterizedBeanPropertyRowMapper.newInstance(Param.class); 
		List<Param> list=this.jdbcTemplate.query(sql,sr);
		return list;
	}

}
